<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../include/base.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">	
	<title>CRM-deal-list</title>
	<meta charset="UTF-8">
	<%@ include file="../include/head.jsp" %>
</head>

<body class="crm">
	
<jsp:include page="../include/top.jsp">
	<jsp:param value="deal" name="tag"/>
</jsp:include>


<div class="container-fluid">
	<div class="row-fluid">
	
	<div class="span8">
	<div class="well screen">
		<div class="page-header header">
						
			<table style="margin:0;"><tbody><tr>
				<td width="68">
					<span style="display:inline-block;background: url(${basePath}/img/workxp_sprites.png) no-repeat scroll -224px -56px transparent; width: 55px; padding-top: 55px;"></span>
				</td>
				<td>编辑机会</td>
			</tr></tbody></table>

		</div>
		<div class="live_search_spinner" behavior="spinner" id="parties_loading">
		  <div class="liner">
		    <h3>处理中...</h3>
		    <img src="${basePath }/img/indicator.gif" alt="mecrm">
		  </div>
		</div>
		<div class="main" id="main">
						

		<div style="padding:0 68px;">
			<form accept-charset="UTF-8" action="${basePath }/deal/update" class="simple_form form-vertical" id="chance_form" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="KFONXAgrV80PCacx2RHhLc5VP7xbjWRF+58BzWueBLs="></div>
				
				<div class="control-group string optional  marco_polo_container">
					<label class="string optional control-label" for="chance_contact"> 联系人</label>
					<div class="controls">
						<input type="hidden" name="id" value="${deal.id }"/>
						<input class="input-xlarge mp_input" data-selected="" id="contact_name" name="contact.name" type="text" autocomplete="off"><ul class="typeahead dropdown-menu mp_list" style="display: none; "></ul>
						<input id="chance_contact_id" name="contact.id" type="hidden" value="">
						<p class="help-block">输入联系人姓名或公司名称（并从下拉提示列表中选取一个）</p>
					</div>
				</div>
				
				<!-- query contacts -->
				<script type="text/javascript" charset="utf-8">
					$(document).ready(function() {
						$('#contact_name').marcoPolo({
						  url: '${basePath}/contact/searchForList',
						  formatItem: function (data, $item) {
						    var ns = data.name;
								if(data.companyname) ns = ns + data.companyname;
								return ns;
						  },
						  onSelect: function (data, $item) {
								var ns = data.name;
								if(data.companyname) ns = ns + data.companyname;
						    $('#contact_name').val(ns);
								$('#chance_contact_id').val(data.id);
						  },
							formatNoResults: function(q, $item) {
								return '';
							}
						});
						
						validate_form('#chance_form');
						$('#chance_name').focus();
					});
				</script>
				
				
				
				<div class="control-group string required">
					<label class="string required control-label" for="chance_name"><abbr title="required">*</abbr> 机会名称</label>
					<div class="controls">
						<input class="string required input-xlarge" id="chance_name" name="deal.title" value="${deal.title }" size="50" type="text">
					</div>
				</div>
		
				<div class="control-group text optional">
					<label class="text optional control-label" for="chance_description"> 机会描述或背景信息</label>
					<div class="controls">
						<textarea class="text optional content" cols="40" id="chance_description" name="deal.content" rows="20">${deal.content }</textarea>
					</div>	
				</div>
				
				<div class="control-group float optional">
					<label class="float optional control-label" for="chance_price"> 金额</label>
					<div class="controls">
						<div class="input-prepend">
							<span class="add-on">元</span>
							<input class="numeric float optional price" id="chance_price" name="deal.money" value="${deal.money }" type="text">
							<input id="chance_price_type" name="chance[price_type]" type="hidden" value="fixed">
							<select id="price_type_pulldown" name="type_pulldown" onchange="Deals.selectBidType(this)"><option value="fixed" selected="selected">固定价</option>
								<option value="hour">每小时</option>
								<option value="month">每月</option>
								<option value="year">每年</option>
							</select>
							<span id="special_bid" style="display:none;">共
								<input id="chance_duration" name="chance[duration]" size="30" style="width:50px;" type="text">
								<span id="time_unit"></span>
							</span>
						</div>
					</div>
				</div>		
				<div class="control-group integer optional">
				<label class="integer optional control-label" for="chance_category_id"> 分类</label>
					<div class="controls">
						<select data="ChanceCategory" id="chance_category_id" name="dealtype.id" onchange="changeCategory(this)">
							<option value="" id="deal-type">无</option>
							<c:forEach items="${dealtypeList }" var="type">
								<c:choose>
									<c:when test="${type.id == dealtype.id }">
										<option value="${type.id }" selected="selected">${type.type }</option>
									</c:when>
									<c:otherwise>
										<option value="${type.id }">${type.type }</option>
									</c:otherwise>
								</c:choose>
							</c:forEach>
							<option value="newtype">新建分类 ...</option>
						</select>
						<a href="https://1339135738.workxp.info/crm_categories?type=chance">编辑分类</a>
					</div>
				</div>
				<script type="text/javascript">
					$(document).ready(function(){
						$("option[value='newtype']").click(function(){
							var str = prompt("new type..");
							if(str){
								$.post("${basePath}/deal/addtype",{"dealtype.type":str},function(obj){
									$("#deal-type").after("<option value='"+obj.id+"'>"+obj.type+"</option>");
								});
							}
						});
					});
				</script>			
				<div class="control-group select optional">
					<label class="select optional control-label" for="chance_assigned_user_id"> 谁负责？</label>
					<div class="controls">
						<select class="select optional" id="chance_assigned_user_id" name="user.id">
							<option value="">无</option>
							<c:forEach items="${userList }" var="u">
								<c:choose>
									<c:when test="${user.id == u.id }">
										<option value="${u.id }" selected="selected">${u.username }</option>
									</c:when>
									<c:otherwise>
										<option value="${u.id }">${u.username }</option>
									</c:otherwise>
								</c:choose>
							</c:forEach>
						</select>
					</div>
				</div>
						
				<!-- 权限 -->
				<div class="control-group string optional"><label class="string optional control-label" for="person_access_policy"> 谁可以看见？</label>
				<div class="controls">
			
					<div id="select_access_policy_for_Contact_" class="select_access_policy">
						<div class="radio scope activated">
							<input checked="checked" id="person_access_policy_attributes_scope_everyone" name="deal.view" type="radio" value="a"> 所有同事
						</div>
						<div class="radio scope ">
							<input id="person_access_policy_attributes_scope_owner" name="deal.view" type="radio" value="m:${sessionScope.user.id }"> 只有我能看见
						</div>
						<div class="radio scope ">
							<input id="person_access_policy_attributes_scope_namedgroup" name="contact.view" type="radio" value="NamedGroup"> 选择一个组...
							<div class="editor">
						  	<select class="named_group" id="group" name="deal.view">
						  		<option value="">选择一个组</option>
								<c:forEach items="${groups }" var="group">
									<option value="m:${sessionScope.user.id},g:${group.id }">${group.groupname }</option>
								</c:forEach>
								
							</select> 
							</div>
						</div>
						<div class="radio scope">
							<input id="person_access_policy_attributes_scope_adhocgroup" name="contact.view" type="radio" value="AdhocGroup"> 选择同事...
							<div class="editor">
					  		<select class="new_adhoc_group_member" id="member" name="deal.view">
					  			<option value="">选择一个同事</option>
					  			<c:forEach items="${users }" var="user">
					  				<c:if test="${user.id != sessionScope.user.id}">
					  					<option value="m:${sessionScope.user.id},u:${user.id}">${user.username }</option>
					  				</c:if>
					  			</c:forEach>
						  		
							</select> 
							</div>
						</div>
					</div>
				</div>
	

			<script type="text/javascript">
				var container = $('#select_access_policy_for_Contact_');
				$('.scope input[type=radio]', container).live('click', function(event) {
					var activated = $(event.target).parent();
					$('.scope.activated', container).removeClass('activated');
					activated.addClass('activated');
						//changePermission();
				  });
				
				$(document).ready(function(){
					
					$("#group").change(function() {
						$("#person_access_policy_attributes_scope_namedgroup").attr("value",$("#group").val());
					});
					
					$("#member").change(function() {
						$("#person_access_policy_attributes_scope_adhocgroup").attr("value",$("#member").val());
					});
				});
	
			</script>
		
			</div>
					
				<div class="form-actions">
					<input class="btn btn-primary" name="commit" onclick="" type="submit" value="修改这个机会">
					<a href="${basePath }/deal/show?id=${deal.id}" class="btn">取消</a>
				</div>
			</form>
		</div>

		</div>
		</div>
	</div>
	
	<div class="span4 sidebar">
		<div class="well">
			<div class="title">什么是机会？</div>
			<p></p><p>机会即业务机会或商业机会，比如一笔可能成交的业务或项目。<br><br>机会通常跟一个<strong>联系人</strong>相关，您需要先将这个联系人添加到系统。<br><br>在输入联系人时，系统会根据已输入的内容自动查找联系人，并以下拉列表的形式显示出来，您可以从中选取一个。<br><br>您可以根据自己的业务情况给机会添加分类。比如按产品分类、按重要程度或行业分类。</p><p></p>
		</div>
	</div>
</div>
</div>
	

</body></html>
